package algorithm;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 返回一个
 */
public class DS {

    ConcurrentHashMap<String, String> ch = new ConcurrentHashMap<>();

    public static void main(String[] args) {
        // given 17 will return 16
        System.out.println(highestOneBit(17));
    }

    /**
     * 返回一个最接近给定数且为２的n次方的数
     * @param i
     * @return
     */
    
    public static int highestOneBit(int i) {
        i |= (i >> 1);
        i |= (i >> 2);
        i |= (i >> 4);
        i |= (i >> 8);
        i |= (i >> 16);
        return i - (i >>> 1);
    }
}
